package com.borened.common.log.controller;

import com.borened.common.core.base.result.PageResult;
import com.borened.common.core.base.result.R;
import com.borened.common.core.mybatisplus.BaseController;
import com.borened.common.log.controller.query.LogQuery;
import com.borened.common.log.domain.SysOperLog;
import com.borened.common.log.service.SysOperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 操作日志接口
 *
 * @author: cch
 * @since: 2022/1/21
 */
@Slf4j
@Api(tags = "系统-操作日志接口")
@RestController
@RequestMapping("/api/v1/system/operlog")
public class SysOperLogController extends BaseController<SysOperLogService, SysOperLog> {

    @Autowired
    private SysOperLogService sysLogService;

    @ApiOperation("分页查询操作日志")
    @GetMapping("/page")
    public R page(LogQuery query) {
        query.setSortCol(null);
        PageResult<SysOperLog> pageResult = executePage(query);
        return R.ok(pageResult);
    }

    @ApiOperation("获取操作日志详细信息")
    @ApiImplicitParam(name = "id", value = "操作日志id", required = true, paramType = "path", dataType = "Number")
    @GetMapping(value = "/{id}")
    public R<SysOperLog> detail(@PathVariable("id") Long id) {
        return R.ok(sysLogService.getById(id));
    }

    @ApiOperation("删除操作日志")
    @ApiImplicitParam(name = "ids", value = "操作日志id数组", required = true, paramType = "path", dataType = "Array")
    @DeleteMapping("/{ids}")
    public R<String> remove(@PathVariable Long[] ids) {
        boolean success = sysLogService.removeByIds(Arrays.asList(ids));
        return R.judge(success);
    }

    @ApiOperation("清空操作日志")
    @DeleteMapping("/clean")
    public R clean() {
        boolean remove = sysLogService.remove(null);
        return R.ok(remove);
    }
}
